<?php error_reporting (E_ALL ^ E_NOTICE);
include('../includes/config.php');
function connectlogin() {
$account = mysql_connect(''.MYSQL_HOST.'', ''.MYSQL_USER.'', ''.MYSQL_PASS.'') or trigger_error(mysql_error(),E_USER_ERROR);
mysql_select_db(''.MYSQL_BASE_LS.'', $account); 
}
function connectgame() {
$game = mysql_connect(''.MYSQL_HOST.'', ''.MYSQL_USER.'', ''.MYSQL_PASS.'') or trigger_error(mysql_error(),E_USER_ERROR); 
mysql_select_db(''.MYSQL_BASE_GS.'', $game);
}
function connectshop() {
$shop = mysql_connect(''.MYSQL_HOST.'', ''.MYSQL_USER.'', ''.MYSQL_PASS.'') or trigger_error(mysql_error(),E_USER_ERROR); 
mysql_select_db(''.MYSQL_BASE_SHOP.'', $shop);
}
//Account Managment Area
function cryptPassword($password)
{
	if($password != "")
		return mysql_escape_string(base64_encode(pack("H*", sha1(utf8_encode($password)))));
}
function isEmail($email) {
	return(preg_match("/^[-_.[:alnum:]]+@((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i",$email));
}
function getskin($shopid) {
connectshop();
	//mysql_query("SET NAMES $database_encoding");
	$query = mysql_query("SELECT * FROM `settings` where `id` = '$shopid'");
	$result = mysql_fetch_array($query);
	return $result['theme'];
}

function recently_reg() {
connectlogin();
	echo "<h2>5 Recently Registered</h2>";
	
	$sql = "SELECT * FROM account_data ORDER BY id DESC LIMIT 0, 5"; 
	$result = mysql_query($sql);
	
	// Check that at least one row was returned 
	$rowCheck = mysql_num_rows($result); 
	
	if($rowCheck > 0) { 
	
	// Show recently registered users
	
	echo "<ul class='column_result'>";
	
		echo '<li><span class="result_column" style="width: 15%;">Username</span><span class="result_column" style="width: 25%;">Real Name</span><span class="result_column" style="width: 35%;">E-Mail Address</span><span class="result_column">Registered Date</span></li>';
	
		while($row = mysql_fetch_array($result)) { 
		
			if($row['access_level'] >= 1) { $admin = " <span style='color: #08c;'>*</span>"; }
			else { $admin = ""; }
			if($row['membership'] == 1) { $restrict = " <span style='color: #8a1f11;'>*</span>"; }
			else { $restrict = ""; }
			$timestamp = strtotime($row['expire']);
			$reg_date = date('d M y @ H:i' ,$timestamp);
		
			echo '<li><a href="user_edit.php?uid='.$row['id'].'"><span class="result_column" style="width: 15%;">'. $row['name'] . $admin . $restrict .'</span><span class="result_column" style="width: 25%;">'.$row['fname'].' '.$row['lname'].'</span><span class="result_column" style="width: 35%;">'.$row['email'].'</span><span class="result_column">'.$reg_date.'</span></a></li>';
			
			// Clear the variable
			
			$admin = "";
			$restrict = "";
		
		}
	
	echo "</ul>";	
	
	} else { echo "Sorry, there are no recently registered users."; }
	
}

function usr_total() {
	
	$sql = "SELECT COUNT(*) FROM account_data"; 
	$result = mysql_query($sql);
	$row = mysql_fetch_array($result);
	
	return '<span class="totals"><i><b>'.$row['COUNT(*)'].'</b> Members</i></span>';
	
}

function usr_active_total() {
	
	$sql = "SELECT COUNT(*) FROM account_data WHERE membership = '0'"; 
	$result = mysql_query($sql);
	$row = mysql_fetch_array($result);
	
	return '<span class="totals"><i><b>'.$row['COUNT(*)'].'</b> Active Members</i></span>';
	
}

function items_total() {
connectshop();
	$sql = "SELECT COUNT(*) FROM items"; 
	$result = mysql_query($sql);
	$row = mysql_fetch_array($result);
	
	return $row['COUNT(*)'];

}
function shop_list() {
connectshop();
    echo "<h2>Game Shop Items</h2>";
	
	$sql = "SELECT * FROM items ORDER BY id DESC"; 

	$result = mysql_query($sql);
	
	// Check that at least one row was returned 
	$rowCheck = mysql_num_rows($result); 
	
	if($rowCheck > 0) { 
	
	// Show recently registered users
	
	echo "<ul class='column_result'>";
	
		echo '<li><span class="result_column" style="width: 25%;">Item Name</span><span class="result_column" style="width: 25%;">Code</span><span class="result_column" style="width: 25%;">Price</span><span class="result_column">Amount</span></li>';
	
		while($row = mysql_fetch_array($result)) { 
		
	
			echo '<li><span class="result_column"><a class="yg-iconmedium yg-notext" href="http://aion.yg.com/item/'.$row['name'].'?id='.$row['code'].'" onclick="return false">.</a></span><a href="item_edit.php?iid='.$row['id'].'"><span class="result_column" style="width: 25%;">'. $row['name'].'</span><span class="result_column" style="width: 25%;">'.$row['code'].'</span><span class="result_column" style="width: 25%;">'.$row['price'].'</span><span class="result_column" style="width: 25%;">'.$row['amount'].'</span></a></li>';
			
			// Clear the variable
			
		}
	
	echo "</ul>";	
	
	} else { echo "Sorry, there are no items."; }

}
function news_list()
{
connectshop();
$sql = "SELECT * FROM news ORDER BY id DESC"; 
	$result = mysql_query($sql);
	
	// Check that at least one row was returned 
	$rowCheck = mysql_num_rows($result); 
	
	if($rowCheck > 0) {
	echo "<ul class='column_result'>";
	echo '<li><span class="result_column" style="width: 25%;">ID</span><span class="result_column" style="width: 25%;">Post</span><span class="result_column">Date</span></li>'; 
	while($row = mysql_fetch_array($result)) { 
	echo '<li><a href="news_edit.php?nid='.$row['id'].'"><span class="result_column" style="width: 25%;">'. $row['id'].'</span><span class="result_column" style="width: 25%;">'.$row['title'].'</span><span class="result_column" style="width: 25%;">'.$row['date'].'</span></a></li>';
	}
	}
	else { echo'There are no posts';}
}
?>